package mfuny.ggongal.admin.ad;

import java.util.Date;
import java.util.HashMap;

import mfuny.ggongal.admin.Server;
import mfuny.ggongal.admin.debug.Debug;
import mfuny.ggongal.admin.etc.Module;


public class AdDetail {
	
	//vc-27~29 업데이트 날짜.
	@SuppressWarnings("deprecation")
	public static final Date vc27Date = new Date(2014-1900, 9-1, 1);		//9월 1일.
	public static final int vc27Hour = 3;														//3시간.
	public static final int vc27Minute = 0;													//정시에 갱신 마감.
	
	@SuppressWarnings("deprecation")
	public static final Date vc23Date = new Date(2014 - 1900, 5, 27);
	public static final int vc23Hour = 3;
	public static final int vc23Minute = 2;
	
	
	
	//특정 광고번호, 오늘 시작 시간 구하기.
	@SuppressWarnings("deprecation")
	public static int ad_getHourToday(AdDao ad) throws Exception {
		int hour = -1;
		Date today = new Date();
		
		try{
			String[] days = ad.getDays().split(",");
			for(int i = 0; i < days.length; ++i) {
				String[] dayAndTime = days[i].split("/");
				Date adDate = Module.strToDate(dayAndTime[0]);
				//년 월 일이 같은지 여부.
				if( today.getYear() == adDate.getYear() && today.getMonth() == adDate.getMonth() && today.getDate() == adDate.getDate()) {
					hour = Integer.parseInt(dayAndTime[1]);
					break;
				}
			}
		} catch(Exception e) {
			try {
				Debug.toDebugFile(e, "ad_getHourToday / level 1 error");
				today.setHours(0);
				today.setMinutes(0);
				today.setSeconds(0);
				
				HashMap<String, Object> paramMap = new HashMap<String, Object>();
				paramMap.put("ad_no", ad.getNo());
				paramMap.put("days", today);
				hour = (Integer) Server.getSqlMapper().queryForObject("time_selectTodayHour", today);
			} catch ( Exception e2 ) {
				Debug.toDebugFile(e2, "ad_getHourToday / level 2 error");
				hour = -1;
			}
			
		}
		
		return hour;
	}
	
	//특정 경품게임의 Date 가져오기 (하나의 날짜).
	public static Date ad_getDateForSGame(AdDao ad) throws Exception {
		String[] spStr = ad.getDays().split("/");
		String dateStr = null;
		Date date = null;
		try {
			dateStr = spStr[0] + " " + spStr[1] + ":00:00";
			date = Module.strToDate(dateStr);
		} catch (Exception e ) {
			date = new Date();
		}
		
		return date;
	}
}
